#include "StdAfx.h"
#include "NoteObj.h"


CNoteObj::CNoteObj()
	: CDisplayObj((CEntityObj*)NULL)
{
	m_lLayerId = 0;
	m_dblPosX = 0;
	m_dblPosY = 0;
	m_lZOrder = 0;
	m_pParent = NULL;
	m_lParentId = 0;
}

CNoteObj::CNoteObj(long lLayerId, double posX, double posY)
	: CDisplayObj((CEntityObj*)NULL)
{
	m_lLayerId = lLayerId;
	m_dblPosX = posX;
	m_dblPosY = posY;
	m_lZOrder = 0;
	m_pParent = NULL;
	m_lParentId = 0;
}


CNoteObj::~CNoteObj(void)
{
}

bool CNoteObj::IsNoteObj() const
{
	return true;
}

bool CNoteObj::IsTextNote() const
{
	return false;
}



bool CNoteObj::IsGroundSymbol() const
{
	return false;
}

eNoteType CNoteObj::GetNoteType() const
{
	return UNKNOW_NOTE;
}

CHoopsMap* CNoteObj::GetHoopsMap()
{
	CSystem* pSystem = CModelObjOption::GetIModelObjEventHandler()->GetActiveSystem();
	if (!pSystem)
	{
		return NULL;
	}

	CLayer* pLayer = pSystem->GetLayerByID(m_lLayerId);
	if (!pLayer)
	{
		return NULL;
	}

	return pLayer->GetHoopsMap();
}


CDisplayObj* CNoteObj::GetParent() 
{
	if (m_pParent==NULL && m_lParentId>0)
	{
		CSystem* pSystem = CModelObjOption::GetIModelObjEventHandler()->GetActiveSystem();
		if (pSystem)
		{
			CEntityObj* pEnt = pSystem->GetEntObjByID(m_lParentId);
			if (pEnt!=NULL)
			{
				m_pParent = pEnt->GetDisplayObjByLayerID(m_lLayerId);
			}
		}
	}

	return m_pParent;
}

void CNoteObj::SetParent(CDisplayObj* pParent)
{
	m_pParent = pParent;
	m_lParentId = pParent->GetEntityObj()->GetId();
}

void CNoteObj::Serialize(CArchive & ar)
{
	if(ar.IsStoring())
	{
		ar<<m_dblPosX;
		ar<<m_dblPosY;
		ar<<m_lParentId;
	}
	else
	{
		ar>>m_dblPosX;
		ar>>m_dblPosY;
		ar>>m_lParentId;
	}

	CDisplayObj::Serialize(ar);
}